# THIS FILE IS LICENSED UNDER THE MIT LICENSE AS OUTLINED IMMEDIATELY BELOW: 
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),  
# to deal in the Software without restriction, including without limitation  
# the rights to use, copy, modify, merge, publish, distribute, sublicense,  
# and/or sell copies of the Software, and to permit persons to whom the  
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in 
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
# DEALINGS IN THE SOFTWARE.

# data.py
# written by: 
#     Jan Jokela <jan@devion.org>

"""
    Devion mediaplex
    Copyright (C) Devion, contributors.
    
    module: Music plugin data manager
    name: /plugins/music/data.py
    desc: Creates data sets and global namespaces for data 
    access in the music plugin.
    devs: Jan (jan@devion.org)
"""

import plugins.data
import base.config.config as config
import engines.audio.player as audioplayer

# Our audio library
audio_library = plugins.data.media_library.get_media_files('audio')
# The audio player
player_driver = config.get_option('app.engines', 'audio', 'str')
audio_player = audioplayer.Generic(player_driver)
# A list with all the albums
albums = {}
for item in audio_library:
    if not item.album in albums:
        albums[item.album] = item.artist, item.album_art
artists = {}
for item in audio_library:
    if not item.artist in artists:
        artists[item.artist] = 0
genres = {}
for item in audio_library:
    if not item.genre in genres:
        genres[item.genre] = 0
        
class Playlist(object):
    def __init__(self):
        self.files = []
    def add(self, audio_object):
        self.files.append(audio_object)
    def rem(self, audio_object):
        try:
            self.files.remove(audio_object)
        except: pass
    def clear(self):
        self.files = []
    def get_next(self, audio_object):
        for k in xrange(len(self.files)):
            if self.files[k] == audio_object: 
                if k == len(self.files) - 1: return self.files[0] 
                else: return self.files[k + 1] 
    def get_previous(self, audio_object):
        for k in xrange(len(self.files)):
            if self.files[k] == audio_object: 
                if k == 0: return self.files[len(self.files) - 1] 
                else: return self.files[k - 1] 

menu_pos = 0
albums_pos = 0
album_pos = 0
artists_pos = 0
artist_pos = 0
genres_pos = 0
genre_pos = 0
album = None
artist = None
genre = None
audio = None
nav = None
playlist = Playlist()

